import pyperclip
from selenium import webdriver
import pyautogui
import time
import base64
import requests
import json
import os
import cookie
import cv2
import numpy as np

pyautogui.FAILSAFE = False


def index():
    # 创建一个Chrome浏览器实例
    driver = webdriver.Chrome()
    # 打开谷歌浏览器，并访问指定的网址
    url = "https://www.baidu.com/s?wd=极速浏览器"
    # 访问url
    driver.get(url)
    time.sleep(20)
    # 放大
    x1, y1 = 890, 30
    pyautogui.moveTo(x1, y1, duration=0.5)
    pyautogui.click()
    time.sleep(1)
    # 检查
    x1, y1 = 110, 500
    pyautogui.moveTo(x1, y1, duration=0.5)
    pyautogui.rightClick()
    time.sleep(1)
    x1, y1 = 120, 900
    pyautogui.moveTo(x1, y1, duration=0.5)
    pyautogui.click()
    time.sleep(1)
    # 移动端
    x1, y1 = 1410, 222
    pyautogui.moveTo(x1, y1, duration=0.5)
    pyautogui.click()
    time.sleep(1)
    # 刷新页面
    x1, y1 = 95, 65
    pyautogui.moveTo(x1, y1, duration=0.5)
    pyautogui.click()
    time.sleep(1)

    # 给页面添加cookie
    cookies = cookie.getCookie()
    for key, value in cookies.items():
        driver.add_cookie({"name": key, "value": value})
    time.sleep(2)
    driver.get(url)

    # 去举报
    # x1, y1 = 850, 580
    x1, y1 = 855, 800
    pyautogui.moveTo(x1, y1, duration=0.5)
    pyautogui.click()
    time.sleep(1)
    # 点击去举报
    x1, y1 = 600, 845
    pyautogui.moveTo(x1, y1, duration=0.5)
    pyautogui.click()
    time.sleep(5)
    return executeReport()


# 去填写举报信息
def executeReport(str=None):
    # 填写举报信息
    x1, y1 = 570, 520
    pyautogui.moveTo(x1, y1, duration=0.5)
    pyautogui.click()
    time.sleep(1)

    # 鼠标滚动
    pyautogui.scroll(-1000)
    time.sleep(1)
    str = '信息与实际不符' if str == None else str
    pyperclip.copy(str)

    # 移动到资料填写
    time.sleep(2)
    x1, y1 = 670, 700
    pyautogui.moveTo(x1, y1, duration=0.5)
    # 点击
    pyautogui.click()
    # 粘贴
    pyautogui.hotkey('ctrl', 'v')

    # 去提交举报
    x1, y1 = 690, 970
    pyautogui.moveTo(x1, y1, duration=0.5)
    # pyautogui.click()
    time.sleep(60)
    return True


# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
    print('开始执行举报')
    res = index()
    if res:
        print('举报完成')
    else:
        print('举报出错')
    exit()
